import flowFactory from "@/flow/flowFactory"
import jsonSeriableUtil from "@/lib/field/core/jsonSeriableUtil"


let nodeWare ={};
let nodeList = [];
let getNode = (nid)=>{
	return nodeWare[nid];
};
function registNode(flowNode){
	nodeWare[flowNode.code] = flowNode;
	nodeList.push(flowNode);
}

function getAllNodeTypes(){
	return flowFactory.getAllFlow();
}

function getAllGroupNodeTypes(){
	return flowFactory.getAllGroupFlow();
}
function fixFlowNodeInfo(flowNode,left,top){
	
}

function seri(text){
	return jsonSeriableUtil.seri(text);
}

function createFlowNode(type,left,top){
	let flowNode = flowFactory.createFlowNode(type);
	flowNode.left = left+"px";
	flowNode.top = top+"px";
	
	fixFlowNodeInfo(flowNode);
	
	registNode(flowNode);
	
	// return {
	// 	id: "1000",
	// 	code: "1000",
	// 	name: "testCreateFlowNode",
	// 	type: "node",
	// 	left: left + 'px',
	// 	top: top + 'px',
	// 	ico: "",
	// 	state: 'success'
	// };
	return flowNode;
}

function searchFlowNode(flowCode){
	return null;
}
function createFlowInfo(name){
	return flowFactory.createFlowInfo(name);
}
function createFlowLine(from, to){
	return flowFactory.createFlowLine(from, to);
}
function createApp(flowInfo, nodeList, lineList,options){
	return flowFactory.createApp(flowInfo, nodeList, lineList,options);
}

const flowApp = {
	install:function(Vue){
	    // 执行初始化 
		flowFactory.loadAll();
	},
	version:"v1.0.0",
	getNode,
	getAllNodeTypes,
	getAllGroupNodeTypes,
	createFlowNode,
	createFlowInfo,
	createFlowLine,
	createApp,
	seri
	
};
export default flowApp;